<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: item.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

class item {
    var $code, $title, $description, $icon, $enabled, $db;

    function __construct() {
		global $order, $db;
		
		$this->code = 'item';
		$this->title = MODULE_SHIPPING_ITEM_TEXT_TITLE;
		$this->description = MODULE_SHIPPING_ITEM_TEXT_DESCRIPTION;
		$this->sort_order = MODULE_SHIPPING_ITEM_SORT_ORDER;
		$this->icon = '';
		$this->tax_class = MODULE_SHIPPING_ITEM_TAX_CLASS;
		$this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false);
		$this->db = $db;
		
		if (($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_ZONE > 0) && isset($order)) {
			$check_flag = false;
			$check = $this->db->db_query("SELECT zone_id FROM ".TABLE_ZONES_TO_GEO_ZONES." WHERE geo_zone_id = '".MODULE_SHIPPING_ITEM_ZONE."' and zone_country_id = '".$order->delivery['country']['id']."' ORDER BY zone_id");
			while(!$check->EOF) {
				if ($check->fields['zone_id'] < 1) {
					$check_flag = true;
					break;
				} elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
					$check_flag = true;
					break;
				}
				$check->MoveNext();
			}
			
			if ($check_flag == false)
				$this->enabled = false;
		}
    }

    function quote($method = '') {
		global $order, $total_count;
		
		$this->quotes = array('id' => $this->code,
			                'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
			                'methods' => array(array('id' => $this->code,
			                                         'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
			                                         'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING)));
		
		if ($this->tax_class > 0)
			$this->quotes['tax'] = get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
		
		if(not_null($this->icon)) 
			$this->quotes['icon'] = image($this->icon, $this->title);
		
		return $this->quotes;
    }

    function check() {
		if (!isset($this->_check)) {
			$check = $this->db->db_query("SELECT configuration_value FROM ".TABLE_CONFIGURATION." WHERE configuration_key = 'MODULE_SHIPPING_ITEM_STATUS'");
			$this->_check = $check->_numOfRows;
		}
		return $this->_check;
    }

    function install() {
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SHIPPING_ITEM_STATUS', 'True', '6', '0', 'cfg_SELECT_option(array(\'True\', \'False\'), ', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_ITEM_ALLOWED', '', '6', '0', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_ITEM_COST', '2.50', '6', '0', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_ITEM_HANDLING', '0', '6', '0', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('MODULE_SHIPPING_ITEM_TAX_CLASS', '0', '6', '0', 'get_tax_class_title', 'cfg_pull_down_tax_classes(', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('MODULE_SHIPPING_ITEM_ZONE', '0', '6', '0', 'get_zone_class_title', 'cfg_pull_down_zone_classes(', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_ITEM_SORT_ORDER', '0', '6', '0', NOW())");
    }

    function remove() {
		$this->db->db_query("DELETE FROM ".TABLE_CONFIGURATION." WHERE configuration_key IN ('".implode("', '", $this->keys())."')");
    }

    function keys() {
		return array('MODULE_SHIPPING_ITEM_STATUS',
					'MODULE_SHIPPING_ITEM_COST',
					'MODULE_SHIPPING_ITEM_HANDLING',
					'MODULE_SHIPPING_ITEM_ALLOWED',
					'MODULE_SHIPPING_ITEM_TAX_CLASS',
					'MODULE_SHIPPING_ITEM_ZONE',
					'MODULE_SHIPPING_ITEM_SORT_ORDER');
    }
}
?>